<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class Person {
            constructor(sex) {
                // 定义了Person中的sex属性
                this.sex = sex
            }
            // 前面的get和set是固定的，都要写。后面写需要管理的属性名
            get sex () {
                console.log('你获取了属性值！');
                return 'none'
            }
            set sex (val) {
                console.log('你设置了属性值！', val);
            }
        }
        let p1 = new Person('nv');
        p1.sex = 'nan';
        console.log(p1.sex);
    </script>
</body>
</html>